﻿#include "pch.h"
#include "CMyMonthCal.h"


IMPLEMENT_DYNAMIC(CMyMonthCal, CBCGPDialog)

CMyMonthCal::CMyMonthCal(CWnd* pParent)
	: CBCGPDialog(IDD_DLG_DATARANGE, pParent),
	m_pNotifyWnd(pParent){

}

CMyMonthCal::~CMyMonthCal(){

}

void CMyMonthCal::DoDataExchange(CDataExchange* pDX){

	CBCGPDialog::DoDataExchange(pDX); 
	DDX_Control(pDX, IDC_MONTHCALENDAR2, m_startCal);
	DDX_Control(pDX, IDC_MONTHCALENDAR3, m_endCal);  
}

BEGIN_MESSAGE_MAP(CMyMonthCal, CBCGPDialog)
	ON_BN_CLICKED(IDOK, &CMyMonthCal::OnOK)
END_MESSAGE_MAP()

BOOL CMyMonthCal::OnInitDialog(){

	CBCGPDialog::OnInitDialog(); 
	return TRUE;
}


BOOL CMyMonthCal::GetStartDate(SYSTEMTIME& st) const{
	/* GetCurSel返回选定的日期，如果成功返回TRUE*/
	return m_startCal.GetCurSel(&st);
}

BOOL CMyMonthCal::GetEndDate(SYSTEMTIME& st) const{

	return m_endCal.GetCurSel(&st);
}
void CMyMonthCal::OnOK(){

	CMonthCalCtrl* pCalStart = (CMonthCalCtrl*)GetDlgItem(IDC_MONTHCALENDAR2);
	CMonthCalCtrl* pCalEnd = (CMonthCalCtrl*)GetDlgItem(IDC_MONTHCALENDAR3);
	if (pCalStart) pCalStart->GetCurSel(m_dtStart);
	if (pCalEnd) pCalEnd->GetCurSel(m_dtEnd);
	if (m_pNotifyWnd) {
		/*用结构体传递日期范围*/
		struct DateRange { 

			COleDateTime start, end; 
		};
		DateRange* pRange = new DateRange{ m_dtStart, m_dtEnd };
		m_pNotifyWnd->SendMessage(WM_DATE_SELECTED, 0, (LPARAM)pRange);
	}
	DestroyWindow();
}
BOOL CMyMonthCal::GetSelectedDates(COleDateTime& dtStart, COleDateTime& dtEnd) const{

	dtStart = m_dtStart;
	dtEnd = m_dtEnd;
	return TRUE;
}
